<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of doggy_admin_m
 *
 * @author Gidaff_01
 */
class doggy_admin_m extends Model {

    //put your code here
    function Doggy_admin_m() {
        parent::Model();
        $this->load->database();
    }

    function count_member() {
        $this->db->select('doggy_accounts.id ,doggy_accounts.account_name,
                doggy_profile.display_name,
                doggy_profile.avatar,
                doggy_race.race_name,
                animus_sub_region.name');
        $this->db->from('doggy_accounts ,doggy_profile ,doggy_race ,animus_sub_region');
        $this->db->where('doggy_accounts.id = doggy_profile.account_id');
        $this->db->where('doggy_accounts.race = doggy_race.id');
        $this->db->where('doggy_accounts.region = animus_sub_region.id');
        $query = $this->db->get();
        return count($query->result_array());
    }

    function get_all_member($per_page, $off_set) {
        $this->db->select('doggy_accounts.id ,doggy_accounts.account_name,
                doggy_profile.display_name,
                doggy_profile.avatar,
                doggy_race.race_name,
                animus_sub_region.name');
        $this->db->from('doggy_accounts ,doggy_profile ,doggy_race ,animus_sub_region');
        $this->db->where('doggy_accounts.id = doggy_profile.account_id');
        $this->db->where('doggy_accounts.race = doggy_race.id');
        $this->db->where('doggy_accounts.region = animus_sub_region.id');
        $this->db->limit($per_page, $off_set);
        $query = $this->db->get();
        return $query->result_array();
    }

    function delete_member($id) {
        $this->db->delete('doggy_profile', array('account_id' => $id));
        return $this->db->delete('doggy_accounts', array('id' => $id));
    }

//////
    function delete_sub_account($id) {
        $tables = array('doggy_albums', 'doggy_message_comments', 'doggy_profile');
        $this->db->where('account_id', $id);
        $this->db->delete($tables);

        $this->db->where('account_id', $id);
        $this->db->or_where('friend_id', $id);
        $this->db->delete('doggy_friends');

        $this->db->where('from_account', $id);
        $this->db->or_where('to_account', $id);
        $this->db->delete('doggy_friend_requests');

        $this->db->where('posted_by', $id);
        $this->db->or_where('to_friends', $id);
        $this->db->delete('doggy_messages');

        $this->db->delete('doggy_wall_messages', array('posted_by' => $id));
        return $this->db->delete('doggy_wall_comments', array('comment_by' => $id));
    }

    function get_race_by_id($id){
        $this->db->select();
        $this->db->from('doggy_race');
        $this->db->where('id', $id);
        $query = $this->db->get();
        return $query;
    }

    function list_race($per_page, $off_set) {
        $this->db->select();
        $this->db->from('doggy_race');
        $this->db->limit($per_page, $off_set);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_race() {
        $this->db->select();
        $this->db->from('doggy_race');
        $query = $this->db->get();
        return count($query->result_array());
    }

    function delete_race($id) {
        return $this->db->delete('doggy_race', array('id' => $id));
    }

    function add_race($data) {
        $query = $this->db->insert('doggy_race', $data);
        return $query;
    }

    function get_exist_race($race_name) {
        $query = $this->db->get_where('doggy_race', array('race_name' => $race_name));
        return $query;
    }

    function edit_race_name($data,$id){
        return $this->db->update('doggy_race', $data, array('id' => $id));
    }

    function get_exist_sub_race($id){
        $query = $this->db->get_where('doggy_accounts', array('race' => $id));
        return $query;
    }

    ///horoscope
    function get_horoscope_by_id($id){
        $this->db->select();
        $this->db->from('doggy_horoscope');
        $this->db->where('id', $id);
        $query = $this->db->get();
        return $query;
    }

    function list_horoscope($per_page, $off_set) {
        $this->db->select();
        $this->db->from('doggy_horoscope');
        $this->db->limit($per_page, $off_set);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_horoscope() {
        $this->db->select();
        $this->db->from('doggy_horoscope');
        $query = $this->db->get();
        return count($query->result_array());
    }

    function delete_horoscope($id) {
        return $this->db->delete('doggy_horoscope', array('id' => $id));
    }

    function add_horoscope($data) {
        $query = $this->db->insert('doggy_horoscope', $data);
        return $query;
    }

    function get_exist_horoscope_name($horoscope_name) {
        $query = $this->db->get_where('doggy_horoscope', array('name' => $horoscope_name));
        return $query;
    }

    function edit_horoscope($data,$id){
        return $this->db->update('doggy_horoscope', $data, array('id' => $id));
    }

    //parkway
    function get_parkway_by_id($id){
        $this->db->select('doggy_parkway.id, doggy_parkway.name,doggy_parkway.description, doggy_parkway.image,doggy_parkway.region_id, animus_sub_region.name as region');
        $this->db->from('doggy_parkway,animus_sub_region');
        $this->db->where('doggy_parkway.region_id = animus_sub_region.id');
        $this->db->where('doggy_parkway.id', $id);
        $query = $this->db->get();
        return $query;
    }

    function list_parkway($per_page, $off_set) {
        $this->db->select('doggy_parkway.id, doggy_parkway.name, doggy_parkway.description, doggy_parkway.region_id, doggy_parkway.image,animus_sub_region.name as region');
        $this->db->from('doggy_parkway,animus_sub_region');
        $this->db->where('doggy_parkway.region_id = animus_sub_region.id');
        $this->db->order_by('doggy_parkway.id DESC');
        $this->db->limit($per_page, $off_set);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_parkway() {
        $this->db->select('doggy_parkway.id, doggy_parkway.name, doggy_parkway.description, doggy_parkway.region_id, doggy_parkway.image,animus_sub_region.name');
        $this->db->from('doggy_parkway,animus_sub_region');
        $this->db->where('doggy_parkway.region_id = animus_sub_region.id');
        $query = $this->db->get();
        return count($query->result_array());
    }

    function delete_parkway($id) {
        return $this->db->delete('doggy_parkway', array('id' => $id));
    }

    function add_parkway($data) {
        $query = $this->db->insert('doggy_parkway', $data);
        return $query;
    }

    function get_exist_parkway_name($parkway_name) {
        $query = $this->db->get_where('doggy_parkway', array('name' => $parkway_name));
        return $query;
    }

    function edit_parkway($data,$id){
        return $this->db->update('doggy_parkway', $data, array('id' => $id));
    }

    function search_parkway($parkway,$per_page, $off_set){
        $this->db->select('doggy_parkway.id, doggy_parkway.name, doggy_parkway.description, doggy_parkway.region_id, doggy_parkway.image,animus_sub_region.name as region');
        $this->db->from('doggy_parkway,animus_sub_region');
        $this->db->where('doggy_parkway.region_id = animus_sub_region.id');
        $this->db->where('doggy_parkway.region_id',$parkway);
        $this->db->order_by('doggy_parkway.id DESC');
        $this->db->limit($per_page, $off_set);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_search_parkway($parkway){
         $this->db->select('doggy_parkway.id, doggy_parkway.name, doggy_parkway.description, doggy_parkway.region_id, doggy_parkway.image,animus_sub_region.name as region');
        $this->db->from('doggy_parkway,animus_sub_region');
        $this->db->where('doggy_parkway.region_id = animus_sub_region.id');
        $this->db->where('doggy_parkway.region_id',$parkway);
        $this->db->order_by('doggy_parkway.id DESC');
        $query = $this->db->get();
        return count($query->result_array());
    }
}

?>
